package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.ClinicRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;

import java.math.BigInteger;

/**
 * @author ：zfr
 * @date ：2021/4/8 17:31
 */
public class ClinicScoreRiseRankCondition extends BaseRankActivityCondition {

    public ClinicScoreRiseRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ClinicScoreRiseRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ClinicScoreRiseRank.getValue(), handle);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ClinicRankArgs args = (ClinicRankArgs)object;
        if (args.getActivityScoreMap().containsKey(activityInfo.getActivityId())) {
            setValue(BigInteger.valueOf(args.getActivityScoreMap().get(activityInfo.getActivityId()).getScore()));
            //重新生成排行榜
            rankChange();
        }
    }
}
